package edu.upc.dao.registro.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import edu.upc.dao.registro.ModificaPerfilSolicitanteDao;
import edu.upc.model.PerfilSolicitante;


@Component
public class ModificaPerfilSolicitanteDaoImpl implements ModificaPerfilSolicitanteDao {

	@Autowired
	private DataSource dataSource;	
	
	@Override
	public boolean modificaPerfilSolicitante(PerfilSolicitante solicitante) {
			
		String sql = "update tb_persona SET nombreRazonSocial_per = ? , email_per = ? , password_per = ?, id_tipdoc = ?, numeroDocumento_per = ?, direccion_per = ? , telefono_per = ?, celular_per = ?, id_tipper = ? where id_per = ?";

		Connection conn = null;
		PreparedStatement ps = null;
		boolean flagRpta=false;
		try {
			
			conn = dataSource.getConnection();
			ps = conn.prepareStatement(sql);	
			ps.setString(1, solicitante.getNombre());
			ps.setString(2, solicitante.getCorreo());
			ps.setString(3, solicitante.getContrasenhia());
			ps.setString(4, solicitante.getTipoDocumento());
			ps.setString(5, solicitante.getNumeroDocumento());
			ps.setString(6, solicitante.getDireccion());
			ps.setString(7, solicitante.getTelefono());
			ps.setString(8, solicitante.getCelular());
			ps.setString(9, solicitante.getTipoPersona());			
			ps.setInt(10, solicitante.getId());
			
			ps.executeUpdate();
			flagRpta=true;
		} catch (SQLException e) {
			throw new RuntimeException("SQL exception occured inserting!", e);
		} finally {
			if (ps != null) {
				try {
					// Close to prevent database cursor exhaustion
					ps.close();
				} catch (SQLException ex) {
				}
			}
			if (conn != null) {
				try {
					// Close to prevent database connection exhaustion
					conn.close();
				} catch (SQLException ex) {
				}
			}
		}
		
		return flagRpta;
	}
		

}
